package com.cisetech.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cisetech.mapper.bobocai.LContentMapper;
import com.cisetech.service.ContentService;
import com.cisetech.vo.bobocai.LContent;
import com.cisetech.vo.bobocai.LUser;
import com.cisetech.web.bobocai.houtai.LoginController;

@Service
public class ContentServiceImpl implements ContentService{
	Logger log = LoggerFactory.getLogger(ContentServiceImpl.class);
	
	
	@Autowired
	LContentMapper contentMapper;
	//添加文章内容
	@Override
	public String addContent(LContent content,String t) {//t==0的时候查询时加id
		// TODO Auto-generated method stub
		try {
			int i = 0;
			List<LContent> contentlist;
			LUser user = LoginController.getUser();
			if("0".equals(t)){
				contentlist = contentMapper.findColumnContent(content);
			}else{
				contentlist = contentMapper.findContent(content);
			}
			if(user!=null){
				content.setName(user.getName());
			}
			if(contentlist!=null && contentlist.size()>0){
				i=contentMapper.updateContent(content);
			}else{
				i = contentMapper.addContent(content);
			}
			if(i==1){
				return "0";
			}
		} catch (Exception e) {
			log.debug(e.getLocalizedMessage());
			return "1";
			// TODO: handle exception
		}
		return "1";
	}
	//根据条件查询内容
	@Override
	public List<LContent> findContent(LContent content) {
		// TODO Auto-generated method stub
		return contentMapper.findContent(content);
	}
	@Override
	public int updateContent(LContent content) {
		// TODO Auto-generated method stub
		return contentMapper.updateContent(content);
	}
	@Override
	public List<LContent> findColumnContent(LContent content) {
		return contentMapper.findColumnContent(content);
	}
	@Override
	public int deletContents(String id) {
		try {
			contentMapper.deletContents(id);
			return 0;
		} catch (Exception e) {
			return 1;
		}
	}
}
